package org.teamh.connection.json.handler;

import org.teamh.connection.json.event.JsonEventObject;
import org.teamh.game.Start;
import org.teamh.logic.datamodel.*;

public class GuideHandler extends JsonMasterHandler {

	public GuideHandler(Start start, DatamodelManager manager) {
		super(start, manager);
	}
	
	public boolean handleMsg(JsonEventObject json) {
	
		if(json.getSource().startsWith("Guide")) {
			CreepSmashGame game = start.getLogic().getGame();
			if(json.getProperty().equals("creepDescriptions")) {
				String creepMappingID = json.getNewValue();
				CreepTypeToCreepMapping creepMapping = new CreepTypeToCreepMapping(creepMappingID);
				game.getGuide().addCreepTypeToCreepMapping(creepMapping);
				manager.addCreepMapping(creepMapping);
				return true;
			} else if(json.getProperty().equals("towerDescriptions")) {
				String towerMappingID = json.getNewValue();
				TowerTypeToTowerMapping towerMapping = new TowerTypeToTowerMapping(towerMappingID);
				game.getGuide().addTowerTypeToTowerMapping(towerMapping);
				manager.addTowerMapping(towerMapping);
				return true;
			}
			return false;
		} else {
			return false;
		}	
	}
}
